package cn.wit.summit.chwan.ui.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.wit.summit.chwan.R;
import cn.wit.summit.chwan.adapters.CommentDetailAdapter;
import cn.wit.summit.chwan.models.dto.CommentBaseBean;
import cn.wit.summit.chwan.models.dto.CommentDetailBean;
import cn.wit.summit.chwan.models.event.DeleteOrModifyCommentEvent;
import cn.wit.summit.chwan.models.event.EnergyEvent;
import cn.wit.summit.chwan.models.request.AddPraiseRequest;
import cn.wit.summit.chwan.models.request.CreateCommentRequest;
import cn.wit.summit.chwan.models.request.DeleteCommentRequest;
import cn.wit.summit.chwan.models.request.GetCommentDetailRequest;
import cn.wit.summit.chwan.models.request.GetCommentTokenRequest;
import cn.wit.summit.chwan.models.response.AddPraiseResponse;
import cn.wit.summit.chwan.models.response.CodeloginRespone;
import cn.wit.summit.chwan.models.response.CreateCommentResponse;
import cn.wit.summit.chwan.models.response.GetCommentTokenResponse;
import cn.wit.summit.chwan.models.response.ResponseBase;
import cn.wit.summit.chwan.net.RpcConstant;
import cn.wit.summit.chwan.retrofit.ApiUtil;
import cn.wit.summit.chwan.retrofit.MyCallback;
import cn.wit.summit.chwan.retrofit.RetrofitManager;
import cn.wit.summit.chwan.ui.base.MyActivity;
import cn.wit.summit.chwan.ui.base.MyApplication;
import cn.wit.summit.chwan.utils.AESUtils;
import cn.wit.summit.chwan.utils.AccountBean;
import cn.wit.summit.chwan.utils.AccountUtil;
import cn.wit.summit.chwan.utils.DateUtils;
import cn.wit.summit.chwan.utils.IntentUtil;
import cn.wit.summit.chwan.utils.LogUtils;
import cn.wit.summit.chwan.utils.NetWorkUtils;
import cn.wit.summit.chwan.utils.PreferenceUtil;
import cn.wit.summit.chwan.utils.StringToUnicodeUtil;
import cn.wit.summit.chwan.utils.StringUtils;
import cn.wit.summit.chwan.utils.UtilsMy;
import cn.wit.summit.chwan.widgets.AddNickDialog;
import cn.wit.summit.chwan.widgets.ClearEditText;
import cn.wit.summit.chwan.widgets.CopyTextView;
import cn.wit.summit.chwan.widgets.CurrencyPromptDialog;
import cn.wit.summit.chwan.widgets.MyDialog;
import cn.wit.summit.chwan.widgets.refreshLayout.SmartRefreshLayout;
import cn.wit.summit.chwan.widgets.refreshLayout.api.RefreshLayout;
import cn.wit.summit.chwan.widgets.refreshLayout.listener.OnLoadMoreListener;
import cn.wit.summit.chwan.widgets.refreshLayout.listener.OnRefreshListener;
import retrofit2.Retrofit;

/**
 * Created by Alan on 2018/4/22.
 */

public class CommentDetailActivity extends MyActivity implements CommentDetailAdapter.Listener {

    @Bind(R.id.commentDetailLv)
    ListView commentDetailLv;
    @Bind(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    @Bind(R.id.edit_user_comment)
    ClearEditText editUserComment;
    @Bind(R.id.btn_chat_send)
    Button btnChatSend;
    @Bind(R.id.inputLl)
    LinearLayout inputLl;

    private String commentId;
    private String gameId;
    private CommentBaseBean bean;

    private CommentDetailAdapter mAdapter;
    private List<CommentDetailAdapter.ViewBean> dataSet = new ArrayList<>();
    private List<CommentBaseBean> allSubCommentBeanXs = new ArrayList<>();

    private View headView;
    private LinearLayout commentDetailTopLl;
    private SimpleDraweeView appIcon;
    private SimpleDraweeView usericon;
    private TextView gameName;
    private TextView username;
    private TextView isMe;
    private TextView time;
    private TextView content;
    private CopyTextView content2;
    private TextView more;
    private ImageView isGood;
    private LinearLayout editLl;
    private TextView editTx;
    private TextView deleteTx;
    private TextView phoneModle;
    private ImageView parise;
    private TextView pariseNumber;
    private ImageView down;
    private TextView downNumber;
    private ImageView message;
    private TextView messageNumber;

    private int pn = 1;
    private int pc = 20;
    private CommentBaseBean mainCommentBean = null;//主评论

    private String replyUserName;
    private String replyUid;
    private String replyCommentId;
    private String replyMainCommentId;
    private String replyContent;
    private String replyPositionID = "";
    private int replyPn = 1;

    private String comentToken = "-1";
    private int uId;
    private String uToken;
    private String uHeadUrl;
    private String uName;
    private boolean isError = false;

    private AddNickDialog addNickDialog;

    private RetrofitManager retrofitManager;
    private Retrofit retrofitComment;
    private ApiUtil apiComment;
    private Retrofit retrofitLogin;
    private ApiUtil apiLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //让布局向上移来显示软键盘
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        setContentView(R.layout.activity_comment_detail);
        ButterKnife.bind(this);

        retrofitManager = RetrofitManager.getInstance(mContext);
        retrofitComment = retrofitManager.getCommentRetrofit();
        apiComment = retrofitComment.create(ApiUtil.class);
        retrofitLogin = retrofitManager.getLoginRetrofit();
        apiLogin = retrofitLogin.create(ApiUtil.class);

        initData();
        initView();
    }

    @Override
    protected void onResume() {
        super.onResume();
        comentToken = PreferenceUtil.getPreferences(mContext, PreferenceUtil.PRE_COMMENT_TOKEN);
        if (StringUtils.isEmpty(comentToken) || comentToken.equals("-1")) {
            getCommentToken();
        }

        if (AccountUtil.getInstance().getAccountData()!=null) {
            uId = AccountUtil.getInstance().getUid();
            uToken = AccountUtil.getInstance().getToken();
            uHeadUrl = AccountUtil.getInstance().getAccountData().getAvatar();
            uName = AccountUtil.getInstance().getAccountData().getNickname();
        }
    }

    private void initData() {
        Intent intent = getIntent();
        bean = (CommentBaseBean) intent.getSerializableExtra("data");
        commentId = intent.getStringExtra("commentId");
        if(bean!=null)
        gameId = bean.getGame_id();

       String  gameid = intent.getStringExtra("gameid");
       if(StringUtils.isNotEmpty(gameid)&&gameId==null){
           gameId=gameid;
       }
        if (AccountUtil.getInstance().getAccountData()!=null) {
            uId = AccountUtil.getInstance().getUid();
            uToken = AccountUtil.getInstance().getToken();
            uHeadUrl = AccountUtil.getInstance().getAccountData().getAvatar();
            uName = AccountUtil.getInstance().getAccountData().getNickname();
        }

        replyMainCommentId = commentId;
        replyCommentId = commentId;
    }

    private ImageView imTopRight;
    private String sort = "desc";
    private void initView() {
        setBarTitleTx(R.string.comment_detail_title_str);
        imTopRight = setBarRightIv(R.drawable.selector_comment_more);
        imTopRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isError) return;
                showPop();
            }
        });

        initHeaderView();

        mAdapter = new CommentDetailAdapter(mContext, dataSet, this);
        commentDetailLv.addHeaderView(headView);
        commentDetailLv.setAdapter(mAdapter);
        refreshLayout.setEnableAutoLoadMore(true);//开启自动加载功能（非必须）
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
                pn = 1;
                getCommentDetailData();
            }
        });
        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull final RefreshLayout refreshLayout) {
                getCommentDetailData();
            }
        });

//        //触发自动刷新
//        refreshLayout.autoRefresh();
        showLoading("");
        getCommentDetailData();
    }

    private void showPop() {
        View popupView = this.getLayoutInflater().inflate(R.layout.comment_detail_top_popwin, null);
        TextView popListOrderTx = (TextView) popupView.findViewById(R.id.pop_list_order_tx);
        TextView popReportTx = (TextView) popupView.findViewById(R.id.pop_report_tx);

        // 创建PopupWindow对象，指定宽度和高度
        final PopupWindow window = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT
                , ViewGroup.LayoutParams.WRAP_CONTENT);
        // 设置动画
//        window.setAnimationStyle(R.style.popup_window_anim);
        // 设置背景颜色
        window.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
        // 设置可以获取焦点
        window.setFocusable(true);
        // 设置可以触摸弹出框以外的区域
        window.setOutsideTouchable(true);
        // 更新popupwindow的状态
        window.update();
        // 以下拉的方式显示，并且可以设置显示的位置
        window.showAsDropDown(imTopRight, 0, 0);

        if (sort.equals("desc"))
            popListOrderTx.setText("顺序查看");
        else
            popListOrderTx.setText("倒序查看");

        popListOrderTx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                window.dismiss();
                allSubCommentBeanXs.clear();
                dataSet.clear();
                if (sort.equals("desc"))
                    sort = "asc";
                else
                    sort = "desc";
                pn = 1;
                getCommentDetailData();
            }
        });

        popReportTx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                window.dismiss();
                IntentUtil.getInstance().goShareWebActivity(mContext, RpcConstant.forumRootUrl
                        + "/user/comment_report?comment_id=" + commentId);
            }
        });
    }

    private void initHeaderView() {
        headView = LayoutInflater.from(this).inflate(R.layout.comment_detail_head_view, null);
        commentDetailTopLl = (LinearLayout) headView.findViewById(R.id.commentDetailTopLl);
        appIcon = (SimpleDraweeView) headView.findViewById(R.id.appIcon);
        usericon = (SimpleDraweeView) headView.findViewById(R.id.usericon);
        gameName = (TextView) headView.findViewById(R.id.gameName);
        username = (TextView) headView.findViewById(R.id.userName);
        isMe = (TextView) headView.findViewById(R.id.isMe);
        time = (TextView) headView.findViewById(R.id.time);
        content = (TextView) headView.findViewById(R.id.content);
        content2 = (CopyTextView) headView.findViewById(R.id.content2);
        more = (TextView) headView.findViewById(R.id.more);
        isGood = (ImageView) headView.findViewById(R.id.isGood);
        editLl = (LinearLayout) headView.findViewById(R.id.editLl);
        editTx = (TextView) headView.findViewById(R.id.editTx);
        deleteTx = (TextView) headView.findViewById(R.id.deleteTx);
        phoneModle = (TextView) headView.findViewById(R.id.phoneModle);
        parise = (ImageView) headView.findViewById(R.id.parise);
        pariseNumber = (TextView) headView.findViewById(R.id.pariseNumber);
        down = (ImageView) headView.findViewById(R.id.down);
        downNumber = (TextView) headView.findViewById(R.id.downNumber);
        message = (ImageView) headView.findViewById(R.id.message);
        messageNumber = (TextView) headView.findViewById(R.id.messageNumber);
        ImageView moreUpIv = (ImageView) headView.findViewById(R.id.moreUpIv);

        moreUpIv.setVisibility(View.GONE);
        more.setVisibility(View.GONE);
        content.setVisibility(View.GONE);
        content2.setVisibility(View.VISIBLE);

        content2.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {

                String str = "";
                if (Build.VERSION.SDK_INT > 11) {
                    ClipboardManager c = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                    c.setPrimaryClip(ClipData.newPlainText("wufan", content2.getText()));
                    str = c.getText().toString();
                } else {
                    android.text.ClipboardManager c = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                    c.setText(content2.getText());
                    str = c.getText().toString();
                }
                String temp = content2.getText().toString();
                if (str.equals(temp))
                    showToast("已复制到剪贴板！");
                return false;
            }
        });

        commentDetailTopLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isError || StringUtils.isEmpty(gameId)) return;

                IntentUtil.getInstance().goGamedetial(mAty,gameId);
            }
        });

        editTx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isError) return;
                if (mainCommentBean.getUid().equals(String.valueOf(uId))) {
                    if (AccountUtil.getInstance().getUid() == 0) {
                        IntentUtil.getInstance().goLoginActivity(mContext);
                        return;
                    }

                    Intent intent = new Intent(mContext, CommentCreatActivity.class);
                    intent.putExtra("isEdit", true);
                    intent.putExtra("gameId", gameId);
                    intent.putExtra("commentId", commentId);
                    intent.putExtra("phoneModel", mainCommentBean.getMobile_phone_model());
                    intent.putExtra("commentContent", mainCommentBean.getContent());
                    startActivity(intent);
                }
            }
        });

        deleteTx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isError) return;
                final CurrencyPromptDialog dialog = new CurrencyPromptDialog(mContext);
                dialog.show();
                dialog.setTitle(getResources().getString(R.string.comment_dialog_title_str));
                dialog.setMsg(getResources().getString(R.string.comment_dialog_msg_str));
                dialog.setCancleBtn(getResources().getString(R.string.comment_dialog_cancle_str), new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });
                dialog.setOkBtn(getResources().getString(R.string.comment_dialog_ok_str), new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        deleteMyComment();
                        dialog.dismiss();
                    }
                });
            }
        });

        parise.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isFastDoubleClick()) return;
                if (isError) return;
                if (AccountUtil.getInstance().getUid()==0) {
                    IntentUtil.getInstance().goLoginActivity(mContext);
                    return;
                }
                praise(v, pariseNumber, mainCommentBean);
            }
        });

        down.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isFastDoubleClick()) return;
                if (isError) return;
                if (AccountUtil.getInstance().getUid()==0) {
                    IntentUtil.getInstance().goLoginActivity(mContext);
                    return;
                }
                unPraise(v, downNumber, mainCommentBean);
            }
        });

        message.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isError) return;
                String name = mainCommentBean.getUser_name();
                editUserComment.setHint("@" + name==null ? "" : name + "：");
                editUserComment.setFocusable(true);
                editUserComment.setFocusableInTouchMode(true);
                editUserComment.requestFocus();
                InputMethodManager inputManager = (InputMethodManager) editUserComment.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(editUserComment, 0);
                replyCommentId = commentId;
                replyPn = 1;
                replyUserName = mainCommentBean.getUser_name();
                replyUid = mainCommentBean.getUid();
                replyPositionID = "";
            }
        });

        if (bean!=null) {
            setTopComment(bean);
        }
    }

    /**
     * 防止快速点击,启动多个同样的界面
     *
     * @return
     */
    long lastClickTime;
    public boolean isFastDoubleClick() {
        long now = System.currentTimeMillis();
        long timeD = now - lastClickTime;
        lastClickTime = now;
        return timeD <= 500;
    }

    private void deleteMyComment() {
        if (NetWorkUtils.isNetworkConnected(mContext)) {
            comentToken = PreferenceUtil.getPreferences(mContext, PreferenceUtil.PRE_COMMENT_TOKEN);
            if (StringUtils.isEmpty(comentToken) || comentToken.equals("-1")) {
                showToast(getResources().getString(R.string.comment_token_str));
                getCommentToken();
                return;
            }

            DeleteCommentRequest request = retrofitManager.deleteCommentRequest(comentToken, gameId, uId, uToken, commentId, pn);
            apiComment.deleteComment(request).enqueue(new MyCallback<ResponseBase<AddPraiseResponse>>() {
                @Override
                public void onSuccess(ResponseBase<AddPraiseResponse> model) {
                    AddPraiseResponse data = model.getData_info();
                    if (data.getStatus().equals("true")) {
                        EventBus.getDefault().post(new DeleteOrModifyCommentEvent(1, "", 0, 0, ""));
                        finish();
                    } else {
                        showToast(getResources().getString(R.string.comment_item_delete_re_str));
                    }
                }

                @Override
                public void onFailure(int code, String msg) {
                    resultShow(msg, true, 2);
                    if (code==801) {
                        getCommentToken();
                    }
                }
            });
        } else {
            resultShow("网络连接失败，再试试吧~", true, 2);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onChangeComment(DeleteOrModifyCommentEvent event) {
        if (event.getType() == 2) {
            String str = event.getContentStr();
            if (str.contains("EM-")){
                try {
                    str = StringToUnicodeUtil.unicode2String(str);
                } catch (Exception e) {
                    LogUtils.e("---m---e.getMessage():"+e.getMessage());
                }
            }
            content2.setText(str);

            if (event.getMobileType() == null || event.getMobileType().isEmpty()) {
                phoneModle.setVisibility(View.INVISIBLE);
                mainCommentBean.setMobile_phone_model("");
            } else {
                phoneModle.setVisibility(View.VISIBLE);
                phoneModle.setText(event.getMobileType());
            }
        }
    }

    private void unPraise(View v, final TextView tv, final CommentBaseBean mainCommentBean) {
        if (mainCommentBean == null)
            return;
        if (mainCommentBean.getIs_despise() == 1) {
            subDespise();
            ImageView view = (ImageView) v;
            view.setImageResource(R.drawable.down_ic);
            onUnPraise(mainCommentBean, 2);
            return;
        } else {
            mainCommentBean.setIs_despise(1);
        }

        if (AccountUtil.getInstance().getAccountData() != null) {
            ImageView view = (ImageView) v;
            view.setImageResource(R.drawable.downed_ic);
            Animation scaleAnim = AnimationUtils.loadAnimation(mContext, R.anim.scale_reset);
            v.startAnimation(scaleAnim);
            scaleAnim.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    long num = Long.valueOf(tv.getText().toString());
                    tv.setText((num + 1) + "");
                    addDespise();
                    onUnPraise(mainCommentBean, 1);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
        } else {
            IntentUtil.getInstance().goLoginInteractive(mContext);
        }
    }

    public void addDespise() {
        long num = Long.valueOf(mainCommentBean.getDespise_count());
        mainCommentBean.setIs_despise(1);
        mainCommentBean.setDespise_count(num + 1 + "");
    }

    public void subDespise() {
        long num = Long.valueOf(mainCommentBean.getDespise_count());
        mainCommentBean.setIs_despise(0);
        if (num - 1 < 0)
            mainCommentBean.setDespise_count("0");
        else
            mainCommentBean.setDespise_count(num - 1 + "");
    }

    private void onUnPraise(CommentBaseBean bean, int type) {
        if (NetWorkUtils.isNetworkConnected(mContext)) {
            comentToken = PreferenceUtil.getPreferences(mContext, PreferenceUtil.PRE_COMMENT_TOKEN);
            if (StringUtils.isEmpty(comentToken) || comentToken.equals("-1")) {
                getCommentToken();
                return;
            }

            AddPraiseRequest tempRequest = retrofitManager.unPraiseRequest(comentToken, gameId, uId, uToken, commentId, type, pn);
            apiComment.subPraise(tempRequest).enqueue(new MyCallback<ResponseBase<AddPraiseResponse>>() {
                @Override
                public void onSuccess(ResponseBase<AddPraiseResponse> model) {
                    checkReset(2);
                }

                @Override
                public void onFailure(int code, String msg) {
                    if (code==801)
                        getCommentToken();
                    resultShow(msg, true, 2);
                }
            });
        } else {
            resultShow("网络连接失败，再试试吧~", true, 2);
        }
    }

    public void checkReset(int i) {
        if (i==1) {
            resetDespise(1);
        } else {
            resetPraise(1);
        }
        String str = "";
        if (phoneModle.getVisibility()==View.VISIBLE)
            str = phoneModle.getText().toString();

        EventBus.getDefault().post(new DeleteOrModifyCommentEvent(2, content2.getText().toString(), 0, 0, str));
    }

    private void resultShow(String msg, boolean b, int type) {
        showToast(msg);
        if (b) {
            if (type == 1)
                resetPraise(0);
            else
                resetDespise(0);
        }
        EventBus.getDefault().post(new DeleteOrModifyCommentEvent(0, "", 0, 0, ""));
    }

    private void praise(View v, final TextView tv, final CommentBaseBean mainCommentBean) {
        if (mainCommentBean == null)
            return;
        if (mainCommentBean.getIs_praise() == 1) {
            subPraise();
            ImageView view = (ImageView) v;
            view.setImageResource(R.drawable.up_ic);
            topPraise(mainCommentBean, 2);
            return;
        } else {
            mainCommentBean.setIs_praise(1);
        }

        if (AccountUtil.getInstance().getAccountData() != null) {
            ImageView view = (ImageView) v;
            view.setImageResource(R.drawable.uped_ic);
            Animation scaleAnim = AnimationUtils.loadAnimation(mContext, R.anim.scale_reset);
            v.startAnimation(scaleAnim);
            scaleAnim.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    long num = Long.valueOf(tv.getText().toString());
                    tv.setText((num + 1) + "");
                    addPraise();
                    topPraise(mainCommentBean, 1);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
        } else {
            IntentUtil.getInstance().goLoginInteractive(mContext);
        }
    }

    public void addPraise() {
        long num = Long.valueOf(mainCommentBean.getPraise_count());
        mainCommentBean.setIs_praise(1);
        mainCommentBean.setPraise_count(num + 1);
    }

    public void subPraise() {
        long num = Long.valueOf(mainCommentBean.getPraise_count());
        mainCommentBean.setIs_praise(0);
        if (num - 1 < 0)
            mainCommentBean.setPraise_count(0);
        else
            mainCommentBean.setPraise_count(num - 1);
    }

    private void topPraise(CommentBaseBean mainCommentBean, int type) {
        if (NetWorkUtils.isNetworkConnected(mContext)) {
            comentToken = PreferenceUtil.getPreferences(mContext, PreferenceUtil.PRE_COMMENT_TOKEN);
            if (StringUtils.isEmpty(comentToken) || comentToken.equals("-1")) {
                showToast(getResources().getString(R.string.comment_token_str));
                getCommentToken();
                return;
            }

            AddPraiseRequest tempRequest = retrofitManager.addPraiseRequest(comentToken, gameId, uId, uToken, commentId, type, pn);
            apiComment.addPraise(tempRequest).enqueue(new MyCallback<ResponseBase<AddPraiseResponse>>() {
                @Override
                public void onSuccess(ResponseBase<AddPraiseResponse> model) {
                    checkReset( 1);
                }

                @Override
                public void onFailure(int code, String msg) {
                    resultShow(msg, true, 1);
                    if (code==801)
                        getCommentToken();
                }
            });
        } else {
            resultShow("网络连接失败，再试试吧~", true, 1);
        }
    }

    public void resetPraise(int state) {
        long num = Long.valueOf(mainCommentBean.getPraise_count());
        if (mainCommentBean.getIs_praise() == 1) {
            mainCommentBean.setIs_praise(0);
            if (num - 1 < 0)
                mainCommentBean.setPraise_count(0);
            else
                mainCommentBean.setPraise_count(num - 1);
        } else {
            if (state!=1) {
                mainCommentBean.setIs_praise(1);
                mainCommentBean.setPraise_count(num + 1);
            }
        }
        setTopComment(mainCommentBean);
    }

    public void resetDespise(int state) {
        long num = Long.valueOf(mainCommentBean.getDespise_count());
        if (mainCommentBean.getIs_despise() == 1) {
            mainCommentBean.setIs_despise(0);
            if (num - 1 < 0)
                mainCommentBean.setDespise_count("0");
            else
                mainCommentBean.setDespise_count(num - 1 + "");
        } else {
            if (state!=1) {
                mainCommentBean.setIs_despise(1);
                mainCommentBean.setDespise_count(num + 1 + "");
            }
        }
        setTopComment(mainCommentBean);
    }

    private void getCommentDetailData() {
        comentToken = PreferenceUtil.getPreferences(mContext, PreferenceUtil.PRE_COMMENT_TOKEN);
        if (StringUtils.isEmpty(comentToken) || comentToken.equals("-1")) {
            getCommentToken(1);
            return;
        }
        uId = AccountUtil.getInstance().getUid();
        uToken = AccountUtil.getInstance().getToken();

        GetCommentDetailRequest request = retrofitManager.getCommentDetailRequest(comentToken, gameId, commentId, uId, pn, pc, sort);
        apiComment.getCommentDetailRequest(request).enqueue(new MyCallback<ResponseBase<CommentDetailBean>>() {
            @Override
            public void onSuccess(ResponseBase<CommentDetailBean> model) {
                CommentDetailBean data = model.getData_info();
                if (commentDetailLv.getHeaderViewsCount()==0)
                    commentDetailLv.addHeaderView(headView);
                updataUi(data);
            }

            @Override
            public void onFailure(int code, String msg) {
                if (mAdapter.getCount()<=0)
                    isError = true;
                showToast(msg);
                cancelLoading();
                if (code==0)
                    refreshLayout.finishLoadMoreWithNoMoreData();
                else {
                    refreshLayout.finishRefresh();
                    refreshLayout.finishLoadMore();
                }
                if (code==509) {
                    refreshLayout.setEnableRefresh(false);
                    refreshLayout.setEnableLoadMore(false);
                    commentDetailLv.removeHeaderView(headView);
                    dataSet.clear();
                    CommentDetailAdapter.ViewBean viewBean = new CommentDetailAdapter.ViewBean(CommentDetailAdapter.ViewType.DELETED, null);
                    dataSet.add(viewBean);
                    mAdapter.notifyDataSetChanged();
                }
            }
        });
    }

    private void updataUi(CommentDetailBean commitBean) {
        CommentDetailBean.GameInfoBean gameInfoBean = commitBean.getGame_info();//游戏基本信息
        List<CommentBaseBean> subCommentBeanXs = commitBean.getMain_comment();//主评论的评论

        if (pn == 1 && gameInfoBean != null) {
            if (StringUtils.isNotEmpty(gameInfoBean.getGame_ico())) {
                UtilsMy.setNetMatchIconImageRET(this, gameInfoBean.getGame_ico(), appIcon);
            }
            gameName.setText(gameInfoBean.getGame_name());
        }

        if (subCommentBeanXs == null || subCommentBeanXs.size() == 0) {
            refreshLayout.finishLoadMoreWithNoMoreData();
            return;
        }

        int maxItem = 10;
        if (pn == 1 && subCommentBeanXs != null && subCommentBeanXs.size() > 0) {
            mainCommentBean = subCommentBeanXs.get(0);
            mainCommentBean.setPn(pn);
            setTopComment(mainCommentBean);
            subCommentBeanXs.remove(0);
            maxItem = 9;
        }

        if (subCommentBeanXs != null) {
            for (int i = 0; i < subCommentBeanXs.size(); i++) {
                subCommentBeanXs.get(i).setPn(pn);
            }
        }

        showMain(subCommentBeanXs, maxItem);
    }

    private void setTopComment(CommentBaseBean temp) {
        if (temp != null) {
            replyUserName = temp.getUser_name();
            replyUid = temp.getUid();

            UtilsMy.setIconImage(this, temp.getHead_portrait(), usericon);
            if (StringUtils.isEmpty(temp.getUser_name())){
                username.setVisibility(View.GONE);
            } else {
                username.setVisibility(View.VISIBLE);
                username.setText(temp.getUser_name());
            }

            if (temp.getUid().equals("" + uId)) {
                isMe.setVisibility(View.VISIBLE);
                if (temp.getIs_old()==1)
                    editLl.setVisibility(View.GONE);
                else
                    editLl.setVisibility(View.VISIBLE);
            } else {
                isMe.setVisibility(View.GONE);
                editLl.setVisibility(View.GONE);
            }

            String str = temp.getContent();
            if (str.contains("EM-")){
                try {
                    str = StringToUnicodeUtil.unicode2String(str);
                    temp.setContent(str);
                } catch (Exception e) {
                    LogUtils.e("---m---e.getMessage():"+e.getMessage());
                }
            }

            content2.setText(temp.getContent());
            if (temp.getIs_old()==1 || temp.getMobile_phone_model() == null
                    || temp.getMobile_phone_model().isEmpty()) {
                phoneModle.setVisibility(View.INVISIBLE);
            } else {
                phoneModle.setVisibility(View.VISIBLE);
                phoneModle.setText(temp.getMobile_phone_model());
            }
            pariseNumber.setText(temp.getPraise_count() + "");
            downNumber.setText(temp.getDespise_count() + "");
            messageNumber.setText(temp.getReply_count() + "");

            long timel = Long.parseLong(temp.getAdd_times() + "000");
            time.setText(DateUtils.FormatForDownloadTime(timel));

            if (temp.getApproval_rate() != null
                    && Double.valueOf(temp.getApproval_rate()) > 70)
                isGood.setVisibility(View.VISIBLE);
            else
                isGood.setVisibility(View.GONE);

            if (temp.getIs_praise() == 1) {
                parise.setImageResource(R.drawable.uped_ic);
            } else {
                parise.setImageResource(R.drawable.up_ic);
            }

            if (temp.getIs_despise() == 1) {
                down.setImageResource(R.drawable.downed_ic);
            } else {
                down.setImageResource(R.drawable.down_ic);
            }
        }
    }

    private void showMain(List<CommentBaseBean> subCommentBeanXs, int maxItem) {

        isError = false;
        if (pn == 1) {
            commentDetailLv.setVisibility(View.VISIBLE);
            refreshLayout.setVisibility(View.VISIBLE);
            inputLl.setVisibility(View.VISIBLE);
            allSubCommentBeanXs.clear();
            dataSet.clear();
        }
        if (subCommentBeanXs == null) {
//            refreshLayout.finishLoadMore();
            refreshLayout.finishLoadMoreWithNoMoreData();//将不会再次触发加载更多事件
            return;
        }

        allSubCommentBeanXs.addAll(subCommentBeanXs);
        addViewItem(subCommentBeanXs, false);

        if (subCommentBeanXs.size() <= 0) {
            if (pn == 1) {
                cancelLoading();
                refreshLayout.finishRefresh();
            } else {
//                refreshLayout.finishLoadMore();
            }
            refreshLayout.finishLoadMoreWithNoMoreData();//将不会再次触发加载更多事件
        } else {
            if (pn == 1) {
                cancelLoading();
                refreshLayout.finishRefresh();
            } else {
                refreshLayout.finishLoadMore();
            }
            pn++;
        }
        mAdapter.notifyDataSetChanged();
    }

    private void addViewItem(List<CommentBaseBean> subCommentBeanXs, boolean isFirst) {
        for (int i = 0; null != subCommentBeanXs && i < subCommentBeanXs.size(); i++) {
            CommentBaseBean bean = subCommentBeanXs.get(i);
            String str = bean.getContent();
            if (str.contains("EM-")){
                try {
                    str = StringToUnicodeUtil.unicode2String(str);
                    bean.setContent(str);
                } catch (Exception e) {
                    LogUtils.e("---m---e.getMessage():"+e.getMessage());
                }
            }
            CommentDetailAdapter.ViewBean viewBean = new CommentDetailAdapter.ViewBean(CommentDetailAdapter.ViewType.COMMENT
                    , new CommentDetailAdapter.ViewBean.Comment(bean));
            if (isFirst)
                dataSet.add(0, viewBean);
            else
                dataSet.add(viewBean);


            List<CommentBaseBean.SubCommentBean> sub = bean.getSub_comment();
            if (sub != null && sub.size() > 0) {
                CommentDetailAdapter.ViewBean replys = new CommentDetailAdapter.ViewBean(CommentDetailAdapter.ViewType.REPLY
                        , new CommentDetailAdapter.ViewBean.Reply(
                        bean.getId(),
                        bean,
                        0,
                        true
                ));
                if (isFirst)
                    dataSet.add(0, replys);
                else
                    dataSet.add(replys);
            }
        }
    }

    @OnClick({R.id.btn_chat_send})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_chat_send:
                if (isError) return;
                AccountBean accountBean = AccountUtil.getInstance().getAccountData();
                if(accountBean==null) {
                    IntentUtil.getInstance().goLoginActivity(mContext);
                    return;
                }
                replyContent = editUserComment.getText().toString();
                if (replyContent.length() == 0) {
                    showToast("不能发表空字符串");
                    return;
                }
                if (replyContent.length() < 3 || replyContent.length()>3000) {
                    showToast(getResources().getString(R.string.comment_sub_str));
                    return;
                }
                hideSoftInput(editUserComment);
                if (accountBean.getDefaultNickname()==0) {
                    addNickDialog = new AddNickDialog(mContext);
                    addNickDialog.show();
                    addNickDialog.setMsg(uName);
                    addNickDialog.setCancleBtn(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            addNickDialog.dismiss();
                            hideSoftInput(addNickDialog.getCurrencyPromptNickEt());
                        }
                    });
                    addNickDialog.setOkBtn(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            String strNick = addNickDialog.getNick();
                            if (StringUtils.isEmpty(strNick)) {
                                showToast(mContext.getResources().getString(R.string.dialog_add_nick_wran));
                                return;
                            }
                            if (!StringUtils.matchStringLength(strNick, 4, 16)){
                                showToast("昵称格式有误，输入4至16位字母或2至8汉字");
                                return;
                            }
                            modifyNick(strNick);
                        }
                    });
                    hideSoftInput(editUserComment);
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            //设置可获得焦点
                            addNickDialog.getCurrencyPromptNickEt().setFocusable(true);
                            addNickDialog.getCurrencyPromptNickEt().setFocusableInTouchMode(true);
                            //请求获得焦点
                            addNickDialog.getCurrencyPromptNickEt().requestFocus();
                            showSoftInput(addNickDialog.getCurrencyPromptNickEt());
                        }
                    }, 200);
                    return;
                }
//                ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
//                        CommentDetailActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                comentToken = PreferenceUtil.getPreferences(mContext, PreferenceUtil.PRE_COMMENT_TOKEN);
                if (StringUtils.isEmpty(comentToken) || comentToken.equals("-1")) {
                    getCommentToken();
                } else {
                    toCreateComment(replyMainCommentId, replyContent, android.os.Build.MODEL
                            , replyUid, replyUserName, replyCommentId, replyPn);
                }
                break;
        }
    }

    /**
     * 上传网名
     */
    private void modifyNick(final String na) {
        if (NetWorkUtils.isNetworkConnected(CommentDetailActivity.this)) {
            showLoading("修改中...");

            int uid = MyApplication.accountBean.getUid();
            String token = MyApplication.accountBean.getToken();

            apiLogin.modifyNick(na, uid+"", token).enqueue(new MyCallback<ResponseBase<CodeloginRespone>>() {
                @Override
                public void onSuccess(ResponseBase<CodeloginRespone> model) {
                    showToast("修改成功");
                    AccountBean bean = MyApplication.accountBean;
                    bean.setNickname(na);
                    bean.setDefaultNickname(1);
                    AccountUtil.getInstance().saveAccountData(bean);
                    if (addNickDialog!=null && addNickDialog.isShowing())
                        addNickDialog.dismiss();
                    cancelLoading();
                }

                @Override
                public void onFailure(int code, String msg) {
                    showToast(msg);
                    cancelLoading();
                }
            });
        } else {
            showToast("网络连接失败，再试试吧~");
            cancelLoading();
        }
    }

    private void toCreateComment(String replyMainCommentId, String replyContent, String model
            , String replyUid, String replyUserName, String replyCommentId, int replyPn) {

        CreateCommentRequest request = retrofitManager.replayCommentRequest(comentToken, gameId, uId+"", uToken, uHeadUrl, uName
                , replyContent, replyCommentId, replyUserName, replyUid, 2,replyMainCommentId, replyPn, false);
        apiComment.createComment(request).enqueue(new MyCallback<ResponseBase<CreateCommentResponse>>() {
            @Override
            public void onSuccess(ResponseBase<CreateCommentResponse> model) {
                CreateCommentResponse data = model.getData_info();
                String num = messageNumber.getText().toString().trim();
                if (!StringUtils.isEmpty(num)) {
                    messageNumber.setText((Integer.parseInt(num)+1) + "");
                }
                if (data != null && data.getAdd_comment_energy() > 0) {
                    EnergyEvent energyEvent = new EnergyEvent();
                    energyEvent.setNumber(data.getAdd_comment_energy());
                    EventBus.getDefault().post(energyEvent);
                }
                resultShow4("回复成功！", data.getInfo(), true);
            }

            @Override
            public void onFailure(int code, String msg) {
                if (code == 801) {
                    PreferenceUtil.savePreference(mContext, PreferenceUtil.PRE_COMMENT_TOKEN, "-1");
                    getCommentToken();
                }
                resultShow4(msg, null, false);
            }
        });
    }

    private void resultShow4(String msg, CreateCommentResponse.InfoBean bean, boolean b) {
        showToast(msg);
        if (b && bean!=null) {
            List<CommentBaseBean> subCommentBeanXs = new ArrayList<>();
            CommentBaseBean temp = null;
            if (replyCommentId == commentId) {
                temp = new CommentBaseBean();
                temp.setId(bean.getId());
                temp.setUid(bean.getUid());
                temp.setUser_name(bean.getUser_name());
                temp.setRank(bean.getRank());
                temp.setHead_portrait(bean.getHead_portrait());
                temp.setGame_id(bean.getGame_id());
                temp.setContent(bean.getContent());
                temp.setMobile_phone_model(bean.getMobile_phone_model());
                temp.setPraise_count(bean.getPraise_count());
                temp.setDespise_count(String.valueOf(bean.getDespise_count()));
                temp.setStart_game_count(String.valueOf(bean.getStart_game_count()));
                temp.setStars_score(bean.getStars_score());
                temp.setApproval_rate(bean.getApproval_rate()+"");
                temp.setAdd_times(String.valueOf(bean.getAdd_times()));
                temp.setIs_belong_to(bean.getIs_despise());
                temp.setReply_count(bean.getReply_count());
                temp.setIs_praise(bean.getIs_praise());
                temp.setIs_despise(bean.getIs_despise());
                temp.setIs_old(bean.getIs_old());
                temp.setPn(replyPn);
                temp.setVip_level(bean.getVip_level());
                temp.setSvip_level(bean.getSvip_level());

                subCommentBeanXs.add(0, temp);
                allSubCommentBeanXs.addAll(0, subCommentBeanXs);
                addViewItem(subCommentBeanXs, true);
            } else {
                int replyPosition = -1;
                for (int i=0;i<allSubCommentBeanXs.size();i++) {
                    if (allSubCommentBeanXs.get(i).getId().equals(replyPositionID)) {
                        replyPosition = i;
                    }
                }
                if (replyPosition == -1) return;
                temp = allSubCommentBeanXs.get(replyPosition);
                int childPosition = 0;
                if (replyCommentId!=temp.getId() && temp.getSub_comment()!=null) {
                    int size = temp.getSub_comment().size();
                    for (int i=0;i<size;i++) {
                        if (temp.getSub_comment().get(i).getId().equals(replyCommentId)) {
                            childPosition = i;
                            continue;
                        }
                    }
                }
                CommentBaseBean.SubCommentBean tempSub = new CommentBaseBean.SubCommentBean();
                tempSub.setId(bean.getId());
                tempSub.setUid(bean.getUid());
                tempSub.setUser_name(bean.getUser_name());
                tempSub.setGame_id(bean.getGame_id());
                tempSub.setContent(bean.getContent());
                tempSub.setVip_level(bean.getVip_level());
                tempSub.setSvip_level(bean.getSvip_level());
//                tempSub.setReply_vip_level(bean.getReply_vip_level());
//                tempSub.setReply_svip_level(bean.getReply_svip_level());
                if (temp.getSub_comment()==null) {
                    List<CommentBaseBean.SubCommentBean> sub = new ArrayList<>();
                    sub.add(tempSub);
                    temp.setSub_comment(sub);
                } else {
                    temp.getSub_comment().add(0, tempSub);
                }

                allSubCommentBeanXs.set(replyPosition, temp);
                dataSet.clear();
                addViewItem(allSubCommentBeanXs, false);
            }
            mAdapter.notifyDataSetChanged();
            EventBus.getDefault().post(new DeleteOrModifyCommentEvent(0, "", 0, 0, ""));

            editUserComment.setText("");
            editUserComment.setHint("添加评论");
            replyCommentId = commentId;
            replyPn = 1;
            replyUserName = mainCommentBean.getUser_name();
            replyUid = mainCommentBean.getUid();
            replyPositionID = "";
        }
    }

    @Override
    public void onPraise(final CommentBaseBean bean, final int position, final int type) {
        if (NetWorkUtils.isNetworkConnected(mContext)) {
            comentToken = PreferenceUtil.getPreferences(mContext, PreferenceUtil.PRE_COMMENT_TOKEN);
            if (StringUtils.isEmpty(comentToken) || comentToken.equals("-1")) {
                showToast(getResources().getString(R.string.comment_token_str));
                getCommentToken();
                return;
            }

            AddPraiseRequest tempRequest = retrofitManager.addPraiseRequest(comentToken, gameId, uId, uToken, bean.getId(), type, pn);
            apiComment.addPraise(tempRequest).enqueue(new MyCallback<ResponseBase<AddPraiseResponse>>() {
                @Override
                public void onSuccess(ResponseBase<AddPraiseResponse> model) {
                    EventBus.getDefault().post(new DeleteOrModifyCommentEvent(0, "", 0, 0, ""));
                }

                @Override
                public void onFailure(int code, String msg) {
                    resultShow3(msg, true, position, 1);
                    if (code==801)
                        getCommentToken();
                }
            });
        } else {
            resultShow3("网络连接失败，再试试吧~", true, position, 1);
        }
    }

    private void resultShow3(String msg, boolean b, int position, int type) {
        showToast(msg);
        if (b) {
            if (type == 1)
                mAdapter.resetPraise(position);
        }
        EventBus.getDefault().post(new DeleteOrModifyCommentEvent(0, "", 0, 0, ""));
    }

    @Override
    public void onReplyReply(CommentBaseBean.SubCommentBean sub, int pn, String id) {
        bottomDialog(sub.getId(), sub.getUser_name(), sub.getUid(), id, pn);
    }

    @Override
    public void onReply(CommentBaseBean bean, int position) {
        bottomDialog(bean.getId(), bean.getUser_name(), bean.getUid(), bean.getId(), bean.getPn());
    }

    void bottomDialog(final String childCommentId, final String name, final String uid, final String id, final int pn) {
        final MyDialog mDialog = new MyDialog(mContext, R.style.MyDialog);
        mDialog.setContentView(R.layout.commentdetail_report_dialog);

        TextView replyTv = (TextView) mDialog.findViewById(R.id.replyTv);
        TextView reportTv = (TextView) mDialog.findViewById(R.id.reportTv);
        TextView cancelTv = (TextView) mDialog.findViewById(R.id.cancelTv);

        replyTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(AccountUtil.getInstance()==null){
                    mDialog.dismiss();
                    return;
                }
                if (null != mDialog && mDialog.isShowing()) {
                    mDialog.dismiss();
                    editUserComment.setHint("@" + name + "：");
                    replyCommentId = childCommentId;
                    replyPn = pn;
                    replyUserName = name;
                    replyUid = uid;
                    replyPositionID = id;
                    showInput();
                }
            }
        });

        reportTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialog.dismiss();
                IntentUtil.getInstance().goShareWebActivity(mContext, RpcConstant.forumRootUrl
                        + "/user/comment_report?comment_id=" + replyCommentId);
            }
        });

        cancelTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialog.dismiss();
            }
        });

        mDialog.show();

        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = mDialog.getWindow().getAttributes();
        layoutParams.gravity= Gravity.BOTTOM;
        layoutParams.width= LinearLayout.LayoutParams.MATCH_PARENT;
        layoutParams.height= LinearLayout.LayoutParams.WRAP_CONTENT;

        mDialog.getWindow().getDecorView().setPadding(0, 0, 0, 0);
        mDialog.getWindow().setAttributes(layoutParams);
    }

    private void showInput() {
        editUserComment.setFocusable(true);
        editUserComment.setFocusableInTouchMode(true);
        editUserComment.requestFocus();
        new Handler().postDelayed(new Runnable(){
            public void run() {
                InputMethodManager inputManager = (InputMethodManager) editUserComment.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(editUserComment, 0);
            }
        }, 200);
    }

    private void getCommentToken() {
        getCommentToken(0);
    }

    private void getCommentToken(final int formId) {
        GetCommentTokenRequest tempRequest = retrofitManager.getCommentTokenRequest();
        apiComment.getCommentToken(tempRequest).enqueue(new MyCallback<ResponseBase<GetCommentTokenResponse>>() {
            @Override
            public void onSuccess(ResponseBase<GetCommentTokenResponse> model) {
                GetCommentTokenResponse data = model.getData_info();
                String token = AESUtils.encrypt4Comment(data.getToken() + "|" + data.getTimes());
                comentToken = token;
                PreferenceUtil.savePreference(mContext, PreferenceUtil.PRE_COMMENT_TOKEN, token);
                PreferenceUtil.saveLongPreference(mContext, PreferenceUtil.PRE_COMMENT_TOKEN_TIME, data.getTimes());
                cancelLoading();
                if (formId==1) {
                    getCommentDetailData();
                }
            }

            @Override
            public void onFailure(int code, String msg) {
                PreferenceUtil.savePreference(mContext, PreferenceUtil.PRE_COMMENT_TOKEN, "-1");
                showToast(msg);
                cancelLoading();
            }
        });
    }

}
